package com.mo.lib.ui.dialog

import android.view.Gravity
import android.widget.TextView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mo.lib.R
import com.mo.lib.utils.*
import com.mo.lib.view.recyclerview.KRecyclerView
import com.mo.lib.adapter.BaseRvAdapter

/**
 * @ author：mo
 * @ data：2022/4/25:14:18
 * @ 功能：基于高德地图经纬度，即GCJ02数据体系，外跳APP
 */
class MapNavigationalDiaolg(val endlatitude: Double, val endlongitude: Double, val name: String, var cumList: ArrayList<String>?, val block: (cumBean: String) -> Unit? = {}) :
    BaseDialog( R.layout.dialog_map_navigational) {
    val data = mutableListOf<String>()

    init {
        cumList?.let {
            data.addAll(it)
        }
        if (isInstallMapGaoDe()) {
            data.add("高德导航");
        }
        if (isInstallMapBaiDu()) {
            data.add("百度导航");
        }
        if (isInstallMapTencent()) {
            data.add("腾讯导航");
        }
        dialog.findViewById<KRecyclerView>(R.id.krv_dialog_navigational).adapter = object : BaseRvAdapter<String>(R.layout.dialog_map_navitional_item, data) {
            override fun doWhat(holder: BaseViewHolder, bean: String, position: Int) {
                holder.getView<TextView>(R.id.tv_item_dialog_navitional).text = bean
                holder.itemView.setClick {
                    when (bean) {
                        "高德导航" -> {
                            toMapApp(1, endlatitude, endlongitude, name)
                        }
                        "百度导航" -> {
                            toMapApp(2, endlatitude, endlongitude, name)
                        }
                        "腾讯导航" -> {
                            toMapApp(3, endlatitude, endlongitude, name)
                        }
                        else   -> {
                            block.invoke(bean)
                        }
                    }
                    dialog.dismiss()
                }
            }
        }
        dialog.findViewById<KRecyclerView>(R.id.tv_dialog_navigational_no).setClick {
            this@MapNavigationalDiaolg.dismisss()
        }
    }

    override fun doWhat() {
        setDismissType(DismissType.OTHER)
        dialog.window!!.setGravity(Gravity.BOTTOM)

    }
}